package com.icloud.system.boot.config;

import com.icloud.common.web.config.BaseSdkConfig;
import com.warrenstrange.googleauth.GoogleAuthenticator;
import com.warrenstrange.googleauth.GoogleAuthenticatorConfig;
import com.warrenstrange.googleauth.ICredentialRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Slf4j
@Configuration
public class SdkConfig extends BaseSdkConfig {
    // Google双因子
    @Bean
    public GoogleAuthenticator googleAuthenticator(ICredentialRepository credentialRepository){
        GoogleAuthenticatorConfig authenticatorConfig =  new GoogleAuthenticatorConfig.GoogleAuthenticatorConfigBuilder()
                //.setWindowSize(3)
                .build();
        // 默认30s
        // long timeStepSize = authenticatorConfig.getTimeStepSizeInMillis();
        // 默认3个window
        // int windowSize = authenticatorConfig.getWindowSize();
        //log.info("timeStepSize:{}, windowSize:{}", timeStepSize, windowSize);
        GoogleAuthenticator googleAuthenticator = new GoogleAuthenticator(authenticatorConfig);
        googleAuthenticator.setCredentialRepository(credentialRepository);
        return googleAuthenticator;
    }
}
